# -*- coding: utf-8 -*-
# @File     : services.py
# @Author   : bingjia
# @Time     : 2020/8/5 19:19
# @Desc     :

from django.utils.translation import ugettext_lazy as _

from . import models

role_list = ['负责人', '前端', '后端', '飞手', '算法']
permission = {
    '负责人': {
        'project': {
            'view_project': True,
            'modify_project': True,
            'create_project': True,
            'delete_project': True,
        },
        'data': {
            'view_data': True,
            'modify_data': True,
            'create_data': True,
            'delete_data': True,
        },
        'check': {
            'view_check': True,
            'create_check': True,
            'modify_check': True,
            'delete_check': True,
        },
        'info': {
            'view_info': True,
            'create_info': True,
            'modify_info': True,
            'delete_info': True,
        },
        'role': {
            'view_role': True,
            'create_role': True,
            'modify_role': True,
            'delete_role': True,
        },
        'equipment': {
            'view_equipment': True,
            'create_equipment':True,
            'modify_equipment':True,
            'delete_equipment': True,
        },
        'train': {
            'view_train': True,
            'create_train': True,
            'modify_train': True,
            'delete_train': True,
        },
        'setting': {
            'view_setting': True,
            'create_setting': True,
            'modify_setting': True,
            'delete_setting': True,
        }},
    '前端': {
        'project': {
            'view_project': True,
            'modify_project': False,
            'create_project': False,
            'delete_project': False,
        },
        'data': {
            'view_data': True,
            'modify_data': False,
            'create_data': False,
            'delete_data': False,
        },
        'check': {
            'view_check': True,
            'create_check': False,
            'modify_check': False,
            'delete_check': False,
        },
        'info': {
            'view_info': True,
            'create_info': False,
            'modify_info': False,
            'delete_info': False,
        },
        'role': {
            'view_role': True,
            'create_role': False,
            'modify_role': False,
            'delete_role': False,
        },
        'equipment': {
            'view_equipment': True,
            'create_equipment': False,
            'modify_equipment': False,
            'delete_equipment': False,
        },
        'train': {
            'view_train': True,
            'create_train': False,
            'modify_train': False,
            'delete_train': False,
        },
        'setting': {
            'view_setting': True,
            'create_setting': False,
            'modify_setting': False,
            'delete_setting': False,
        }},
    '后端': {
        'project': {
            'view_project': True,
            'modify_project': False,
            'create_project': False,
            'delete_project': False,
        },
        'data': {
            'view_data': True,
            'modify_data': False,
            'create_data': False,
            'delete_data': False,
        },
        'check': {
            'view_check': True,
            'create_check': False,
            'modify_check': False,
            'delete_check': False,
        },
        'info': {
            'view_info': True,
            'create_info': False,
            'modify_info': False,
            'delete_info': False,
        },
        'role': {
            'view_role': True,
            'create_role': False,
            'modify_role': False,
            'delete_role': False,
        },
        'equipment': {
            'view_equipment': True,
            'create_equipment': False,
            'modify_equipment': False,
            'delete_equipment': False,
        },
        'train': {
            'view_train': True,
            'create_train': False,
            'modify_train': False,
            'delete_train': False,
        },
        'setting': {
            'view_setting': True,
            'create_setting': False,
            'modify_setting': False,
            'delete_setting': False,
        }},
    '飞手': {
        'project': {
            'view_project': True,
            'modify_project': False,
            'create_project': False,
            'delete_project': False,
        },
        'data': {
            'view_data': True,
            'modify_data': False,
            'create_data': False,
            'delete_data': False,
        },
        'check': {
            'view_check': True,
            'create_check': False,
            'modify_check': False,
            'delete_check': False,
        },
        'info': {
            'view_info': True,
            'create_info': False,
            'modify_info': False,
            'delete_info': False,
        },
        'role': {
            'view_role': True,
            'create_role': False,
            'modify_role': False,
            'delete_role': False,
        },
        'equipment': {
            'view_equipment': True,
            'create_equipment': False,
            'modify_equipment': False,
            'delete_equipment': False,
        },
        'train': {
            'view_train': True,
            'create_train': False,
            'modify_train': False,
            'delete_train': False,
        },
        'setting': {
            'view_setting': True,
            'create_setting': False,
            'modify_setting': False,
            'delete_setting': False,
        }},
    '算法': {
        'project': {
            'view_project': True,
            'modify_project': False,
            'create_project': False,
            'delete_project': False,
        },
        'data': {
            'view_data': True,
            'modify_data': False,
            'create_data': False,
            'delete_data': False,
        },
        'check': {
            'view_check': True,
            'create_check': False,
            'modify_check': False,
            'delete_check': False,
        },
        'info': {
            'view_info': True,
            'create_info': False,
            'modify_info': False,
            'delete_info': False,
        },
        'role': {
            'view_role': True,
            'create_role': False,
            'modify_role': False,
            'delete_role': False,
        },
        'equipment': {
            'view_equipment': True,
            'create_equipment': False,
            'modify_equipment': False,
            'delete_equipment': False,
        },
        'train': {
            'view_train': True,
            'create_train': False,
            'modify_train': False,
            'delete_train': False,
        },
        'setting': {
            'view_setting': True,
            'create_setting': False,
            'modify_setting': False,
            'delete_setting': False,
        }
    }
}


def get_project_logo_file_path():
    return ""


def get_project_report_file_path():
    return ""


def get_project_map_file_path():
    return ""


def is_project_already_exist(name, company, full_name):
    """
    判断项目是否已存在
    """

    project_model = models.Project

    if project_model.objects.filter(name=name, owner__full_name=full_name, company=company):
        return (True, _("project is already exist"))

    return (False, None)


def is_membership_already_exist(full_name, project_id, role_name):
    """
    该成员是否已存在
    """
    membership_model = models.Membership

    if membership_model.objects.filter(role__name=role_name,
                                       user__full_name=full_name,
                                       project=models.Project.objects.get(pk=project_id)):
        return (True, _("membership is already exist"))

    return (False, None)


def is_role_already_exist(name, project_id):
    """
    该成员是否已存在
    """
    role_model = models.Role

    if role_model.objects.filter(name=name,
                                 project=models.Project.objects.get(pk=project_id)):
        return (True, _("role is already exist"))

    return (False, None)


